package com.yupi.quizai.config;

import com.zhipu.oapi.ClientV4;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@ConfigurationProperties(prefix = "ai")
@Data
public class AiConfig {

    /**
     * apiKey，需要从开放平台获取
     */
    private String apiKey ;

    @Bean
    public ClientV4 getClientV4() {
        // 添加非空校验，避免空指针
        if (apiKey == null || apiKey.trim().isEmpty()) {
            throw new IllegalArgumentException("AI API密钥不能为空，请检查配置文件");
        }
        return new ClientV4.Builder(apiKey).build();
    }
}
